package homework.valid.validators.impl;

import homework.valid.validators.BaseValidator;

public class EnumValidator extends BaseValidator {

    private Enum[] items;

    public EnumValidator(String msg, Enum[] values) {
        super(msg);
        items = values;
    }

    @Override
    public boolean isValid(Object v) {
        Enum i = getEnumItem((String)v);
        return i != null;
    }

    public Enum getEnumItem(String value) {
        for(Enum i: items) {
            if(i.toString().equals(value))
                return i;
        }
        return null;
    }
}
